package org.accp.controller;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.accp.dao.IndustryDao;
import org.accp.pojo.Complaint;
import org.accp.pojo.Industry;
import org.accp.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/industry")
@CrossOrigin("*")
public class IndustryController {
    @Autowired
    private IndustryDao industryDao;

    public void setIndustryDao(IndustryDao industryDao) {
        this.industryDao = industryDao;
    }
    @RequestMapping("/list")
    @ResponseBody
    public ResponseResult<List<Industry>> list(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit, Industry condition) throws Exception {
        Page<Industry> pager = PageHelper.startPage(page, limit);
        List<Industry> list = industryDao.getConditionList(condition);
        return new ResponseResult(pager.getTotal(),list);
    }
    @RequestMapping("/batchDelete")
    @ResponseBody
    public ResponseResult batchDelete(Integer[] id) throws Exception{
        industryDao.batchDelete(id);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseResult delete(int id) throws Exception{
        industryDao.delete(id);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/add")
    @ResponseBody
    public ResponseResult add(Industry industry) throws Exception{
        industryDao.add(industry);
        return ResponseResult.createSuccessResult();
    }
    @RequestMapping("/update")
    @ResponseBody
    public ResponseResult update(Industry industry) throws Exception{
        industryDao.update(industry);
        return ResponseResult.createSuccessResult();
    }
}
